import { createLoading } from './CreateLoading';
const vLoading = {
    // 当被绑定的元素挂载到 DOM 中时……
    mounted(el: any, binding: any) {
        const fullscreen = false;
        if (!el.getAttribute) {
            return;
        }
        const tip = el.getAttribute('loading-tip');
        const instance = createLoading({
            loading: binding.value,
            tip
        }, fullscreen ? document.body : el);
        el.instance = instance;
    },
    updated(el: any, binding: any) {
        if (!el.instance) {
            return;
        }
        if (!el.getAttribute) {
            return;
        }
        const tip = el.getAttribute('loading-tip');
        const percent = el.getAttribute('loading-percent');
        el.instance.setTip(tip);
        el.instance.setPercent(+percent);
        el.instance.setLoading(binding.value);
    },
    unmounted(el: any) {
        el.instance.close();
    }
};

export const setupProgressLoadingDirective = (app: any) => {
    app.directive('progressLoading', vLoading);
};